package com.lck.blogmanager.controller;

import com.lck.blogmanager.common.Response;
import com.lck.blogmanager.entity.AdminEntity;
import com.lck.blogmanager.req.AdminLoginReq;
import com.lck.blogmanager.req.UpdateAdminInfoReq;
import com.lck.blogmanager.service.AdminService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

/**
 * 管理员
 * @author wyq
 * @version v1.0.0
 * @explain
 * @date 2024/4/7 18:28
 */
@RequestMapping("/admin")
@RequiredArgsConstructor
@Slf4j
@RestController
@CrossOrigin
public class AdminController {

    private final AdminService adminService;

    /**
     * 管理员登录
     * @param req
     * @return
     */
    @PostMapping("/login")
    public Response<String> adminLogin(@RequestBody AdminLoginReq req){
        String token = adminService.adminLogin(req);
        return Response.success(token);
    }

    /**
     * 管理员信息
     * @return
     */
    @GetMapping("/info")
    public Response<AdminEntity> adminInfo(){
        AdminEntity admin = adminService.adminInfo();
        return Response.success(admin);
    }

    /**
     * 重置登录密码
     * @return
     */
    @PostMapping("/reset/password")
    public Response resetPassword(){
        adminService.resetPassword();
        return Response.success();
    }

    /**
     * 修改密码
     * @param req
     * @return
     */
    @PostMapping("/updatePassword")
    public Response updateInfo(@RequestBody UpdateAdminInfoReq req){
        adminService.updateInfo(req);
        return Response.success();
    }


}
